package com.originalpoint.origin_server.controller;

import com.originalpoint.origin_server.pojo.Register;
import com.originalpoint.origin_server.result.RegisterResult;
import com.originalpoint.origin_server.service.RegisterService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/api")
@CrossOrigin
public class RegisterController {

    @Resource
    private RegisterService registerService;

    @ApiOperation(value  = "注册时判断用户是否已经存在")
    @PostMapping("/register")
    public int register(@RequestBody Map<String, Object> request) {
        String username = (String) request.get("loginName");
        String password = (String) request.get("password");
        int role = (int) request.get("role");

        Register register = new Register();
        register.setUsername(username);
        register.setPassword(password);
        register.setRole(role);
        return registerService.register(register);
    }
}
